#ifndef __MEMORYPOOL_H__
#define __MEMORYPOOL_H__

//TODO:待补充
//内存池只能有一个，因此采用单例模式
//不用内存池的话也可以考虑用智能指针来管理内存


class CMemory
{
public:
    static CMemory* GetInstance()
    {
        if (m_instance == nullptr)
        {
            if (m_instance == nullptr) //双重检查，放置线程切换时极端情况导致错误判断
            {
                m_instance = new CMemory();
                static _CG cg;
            }
        }
        return m_instance;
    }

    class _CG
    {
    public:
        ~_CG()
        {
            if (CMemory::m_instance)
            {
                delete CMemory::m_instance;
                CMemory::m_instance = nullptr;
            }
        }
    };


public:
    ~CMemory() {};
    void FreeMemory(char* jobinfo);
    void* AllocMemory(int memsize, bool ifMemset);

private:
    static CMemory* m_instance;
//禁止拷贝，禁止无参构造初始化，只允许单例模式
private:
    CMemory() {};
    CMemory(CMemory &&) = delete;
    CMemory(const CMemory &) = delete;
    CMemory &operator=(CMemory &&) = delete;
    CMemory &operator=(const CMemory &) = delete;

};
#endif // __MEMORYPOOL_H__